package com.xinruke.hostels.systemmanage.controller;

import com.xinruke.hostels.common.controller.BaseController;
import com.xinruke.hostels.common.vo.ResultVO;
import com.xinruke.hostels.common.vo.query.RowsDataVO;
import com.xinruke.hostels.system.manage.interfaces.dto.*;
import com.xinruke.hostels.systemmanage.service.MeetingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;


/**
 * @author yutaipu
 */
@RestController
@RequestMapping("/meeting/")
@Api(tags = "会场")
@Slf4j
public class MeetingController extends BaseController {

    @Autowired
    private MeetingService meetingService;

    @PostMapping("/add")
    @ApiOperation("添加")
    public ResultVO add(@Valid @RequestBody MeetingAddDTO addQueryDTO) {
        return meetingService.add(addQueryDTO);
    }

    @PostMapping("/modify")
    @ApiOperation("修改")
    public ResultVO modify(@Valid @RequestBody MeetingModifyDTO modifyQueryDTO) {
        return meetingService.modify(modifyQueryDTO);
    }

    @PostMapping("/del")
    @ApiOperation("删除")
    public ResultVO delete(@Valid @RequestBody MeetingDelDTO delQueryDTO) {
        return meetingService.delete(delQueryDTO);
    }

    /**
     *通过酒店id查询旗下所有会场
     */
    @PostMapping("/hotel")
    @ApiOperation(value = "查询酒店下的所有会场")
    public ResultVO<RowsDataVO<MeetingQueryResultDTO>> getUnderHotel(@Valid @RequestBody MeetingQueryDTO underHotelQueryDTO) {
        ResultVO<RowsDataVO<MeetingQueryResultDTO>> resultVO = ResultVO.fail();
        RowsDataVO<MeetingQueryResultDTO> dataVO = meetingService.getUnderHotel(underHotelQueryDTO);
        resultVO.setCode(ResultVO.SUCCESS);
        resultVO.setMessage("操作成功");
        resultVO.setData(dataVO);
        return resultVO;
    }

    /**
     * 通过id查询详情
     * @return 会场详情
     */
    @PostMapping("/detail")
    @ApiOperation(value = "查询会场详情")
    public ResultVO<MeetingDetailQueryResultDTO> getDetail(@Valid @RequestBody MeetingDetailDTO detailQueryDTO) {

        MeetingDetailQueryResultDTO detail = meetingService.getDetail(detailQueryDTO);
        ResultVO<MeetingDetailQueryResultDTO> resultVO = ResultVO.success();
        resultVO.setMessage("操作成功");
        resultVO.setData(detail);
        return resultVO;
    }


    /**
     * 获取会场未使用集合
     *
     * @return
     */
    @PostMapping("/getMeetingUnusedList")
    @ApiOperation(value = "获取会场未使用集合")
    public ResultVO<RowsDataVO<MeetingUnusedQueryResultDTO>> getRoomUnusedList(@Valid @RequestBody MeetingUnusedQueryDTO meetingUnusedQueryDTO) {
        ResultVO<RowsDataVO<MeetingUnusedQueryResultDTO>> resultVO = ResultVO.fail();
        RowsDataVO<MeetingUnusedQueryResultDTO> rowsDataVO = meetingService.getMeetingUnusedList(meetingUnusedQueryDTO);
        resultVO.setCode(ResultVO.SUCCESS);
        resultVO.setMessage("SUCCESS");
        resultVO.setData(rowsDataVO);
        return resultVO;
    }

}
